package tjs.study.notes.queue.producer.kafka.initial;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.stereotype.Service;

/**
 * Created by Nicky.Tang on 2022/1/8 4:45 下午
 *
 * @since 02.12.10
 */
@Service
public class InitialKafkaService {
    @Autowired
    private KafkaTemplate<String, String> kafkaTemplate;

    /**
     * 发送消息到kafka
     *
     * 更改分区数（从0开始）
     * kafka-topics.sh --alter  --zookeeper 127.0.0.1:2181 --topic nicky_init --partitions 4
     * kafka-topics.sh --describe  --zookeeper 127.0.0.1:2181 --topic nicky_init
     */
    public void sendMsg(String channel, String message) {
        kafkaTemplate.send(channel == null ? "nicky_init" : channel, message);
    }

}
